﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternFactoryGeneral
{
    class Program
    {
        static void Main(string[] args)
        {
            FactoryA factoryA = new FactoryA();
            factoryA.CreateProduct();

            FactoryB factoryB = new FactoryB();
            factoryB.CreateProduct();
             
            Console.ReadKey();
        }
    }

    #region 工厂类
     
    abstract class Factory
    {
        public abstract Product CreateProduct();
    } 
    //A工厂专门产出A产品
    class FactoryA : Factory
    {
        public override Product CreateProduct()
        {
            return new ProductA();
        }
    }
    //B工厂专门产出B产品
    class FactoryB : Factory
    {
        public override Product CreateProduct()
        {
            return new ProductB();
        }
    }
    
    #endregion

    #region 产品

    //抽象的产品类
    public abstract class Product
    {
        public abstract string GetName();
    } 
    //具体产品A
    public class ProductA : Product
    {
        public ProductA()
        { Console.WriteLine("ProductA start"); }

        public override string GetName()
        {
            return "ProductA";
        }
    } 
    //具体产品B
    public class ProductB : Product
    {
        public ProductB()
        { Console.WriteLine("ProductB start"); }

        public override string GetName()
        {
            return "ProductB";
        }
    }
     
    #endregion





}
